import request from '@/utils/request'

/**
 * 成绩管理API接口
 */

// 分页查询成绩列表
export function getScorePage(currentPage, pageSize, queryParams) {
  return request({
    url: `/api/scores/page/${currentPage}/${pageSize}`,
    method: 'get',
    params: queryParams
  })
}

// 根据ID查询成绩详情
export function getScoreById(scoreId) {
  return request({
    url: `/api/scores/${scoreId}`,
    method: 'get'
  })
}

// 新增成绩
export function addScore(scoreData) {
  return request({
    url: '/api/scores',
    method: 'post',
    data: scoreData
  })
}

// 更新成绩信息
export function updateScore(scoreData) {
  return request({
    url: '/api/scores',
    method: 'put',
    data: scoreData
  })
}

// 删除成绩
export function deleteScore(scoreId) {
  return request({
    url: `/api/scores/${scoreId}`,
    method: 'delete'
  })
}

// 批量删除成绩
export function batchDeleteScores(scoreIds) {
  return request({
    url: '/api/scores/batch',
    method: 'delete',
    data: scoreIds
  })
}

// 批量导入成绩
export function batchImportScores(formData) {
  return request({
    url: '/api/scores/batch-import',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 导出成绩模板
export function exportScoreTemplate() {
  return request({
    url: '/api/scores/export-template',
    method: 'get',
    responseType: 'blob'
  })
}

// 根据项目ID查询成绩列表
export function getScoresByProjectId(projectId) {
  return request({
    url: '/api/scores/by-project',
    method: 'get',
    params: { projectId }
  })
}

// 根据学生ID查询成绩列表
export function getScoresByStudentId(studentId) {
  return request({
    url: '/api/scores/by-student',
    method: 'get',
    params: { studentId }
  })
}

// 根据项目状态查询成绩列表
export function getScoresByProjectStatus(status) {
  return request({
    url: '/api/scores/by-project-status',
    method: 'get',
    params: { status }
  })
}

// 获取成绩排名
export function getScoreRanking(projectId, round = null) {
  return request({
    url: '/api/scores/ranking',
    method: 'get',
    params: { projectId, round }
  })
}

// 统计成绩总数
export function countScores() {
  return request({
    url: '/api/scores/count',
    method: 'get'
  })
}

// 根据项目统计成绩数量
export function countScoresByProject(projectId) {
  return request({
    url: '/api/scores/count-by-project',
    method: 'get',
    params: { projectId }
  })
}

// 获取成绩统计信息
export function getScoreStatistics(projectId = null) {
  return request({
    url: '/api/scores/statistics',
    method: 'get',
    params: { projectId }
  })
}

// 验证成绩数据
export function validateScoreData(scoreData) {
  return request({
    url: '/api/scores/validate',
    method: 'post',
    data: scoreData
  })
}

// 获取成绩单位列表
export function getScoreUnits() {
  return request({
    url: '/api/scores/units',
    method: 'get'
  })
}

// 获取成绩状态列表
export function getScoreStatuses() {
  return request({
    url: '/api/scores/statuses',
    method: 'get'
  })
}

// 批量审核成绩
export function batchAuditScores(auditData) {
  return request({
    url: '/api/scores/batch-audit',
    method: 'post',
    data: auditData
  })
}

// 批量公示成绩
export function batchPublishScores(publishData) {
  return request({
    url: '/api/scores/batch-publish',
    method: 'post',
    data: publishData
  })
}

// 批量驳回成绩
export function batchRejectScores(rejectData) {
  return request({
    url: '/api/scores/batch-reject',
    method: 'post',
    data: rejectData
  })
}

// 处理成绩异议
export function handleScoreDispute(disputeData) {
  return request({
    url: '/api/scores/handle-dispute',
    method: 'post',
    data: disputeData
  })
}

// 导出成绩数据
export function exportScores(exportParams) {
  return request({
    url: '/api/scores/export',
    method: 'get',
    params: exportParams,
    responseType: 'blob'
  })
}

// 导出成绩排名
export function exportScoreRanking(projectId, round = null) {
  return request({
    url: '/api/scores/export-ranking',
    method: 'get',
    params: { projectId, round },
    responseType: 'blob'
  })
}

// 个人成绩查询
export function getPersonalScores(queryParams) {
  return request({
    url: '/api/scores/personal',
    method: 'get',
    params: queryParams
  })
}

// 获取成绩历史记录
export function getScoreHistory(scoreId) {
  return request({
    url: `/api/scores/${scoreId}/history`,
    method: 'get'
  })
}

// 发布成绩排名
export function publishScoreRanking(projectId, round = null) {
  return request({
    url: '/api/scores/publish-ranking',
    method: 'post',
    data: { projectId, round }
  })
}

// 颁发奖牌
export function awardMedal(medalData) {
  return request({
    url: '/api/scores/award-medal',
    method: 'post',
    data: medalData
  })
}

// 生成证书
export function generateCertificate(certificateData) {
  return request({
    url: '/api/scores/generate-certificate',
    method: 'post',
    data: certificateData,
    responseType: 'blob'
  })
}

// 生成分享链接
export function generateShareLink(shareData) {
  return request({
    url: '/api/scores/generate-share-link',
    method: 'post',
    data: shareData
  })
}

// 分享成绩到社交媒体
export function shareScoreToSocial(shareData) {
  return request({
    url: '/api/scores/share-social',
    method: 'post',
    data: shareData
  })
}